import {
  q as l,
  p as N,
  ap as z,
  X as h,
  f as D,
  H as F,
  av as y,
  aw as j,
  k as g,
  l as A,
  as as n,
  at as c,
  au as E
} from "./index-b50e6ef9.js";
import { d as H, e as $, f as q, h as v, a as P } from "./goods-bd9f9b53.js";
function G(_) {
  const u = l([]),
    i = l(!0),
    d = l({});
  N();
  const f = l([]),
    w = l("");
  l(!1);
  const m = l({}),
    b = z("reload"),
    p = h({
      pageSize: 10,
      currentPage: 1,
      pageSizes: [10, 20, 30],
      total: 0,
      align: "right",
      background: !0,
      small: !1
    }),
    B = h({
      text: "正在加载第一页...",
      viewBox: "-10, -10, 50, 50",
      spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    }),
    x = [
      {
        type: "selection",
        width: 55,
        align: "left",
        hide: ({ checkList: e }) => !e.includes("勾选列")
      },
      {
        label: "序号",
        type: "index",
        width: 70,
        hide: ({ checkList: e }) => !e.includes("序号列")
      },
      { label: "ID", prop: "wares_id", minWidth: 50 },
      { label: "商品名称", prop: "wares_name", minWidth: 200 },
      { label: "分类", prop: "type_name", minWidth: 80 },
      { label: "报单价格", prop: "wares_price", minWidth: 120 },
      { label: "免费会员价格", prop: "wares_market_price", minWidth: 120 },
      {
        label: "内含数量",
        prop: "wares_bottle",
        minWidth: 120,
        formatter: ({ wares_bottle: e, wares_unit: a }) => e + " " + a
      },
      { label: "重量", prop: "wares_weight", minWidth: 120 },
      { label: "库存", prop: "wares_stock", minWidth: 120 },
      { label: "销量", prop: "wares_sales", minWidth: 120 },
      {
        label: "图片",
        prop: "wares_img",
        minWidth: 100,
        cellRenderer: e =>
          g("div", null, [
            " ",
            g(
              "img",
              {
                src: e.row.wares_img,
                style: "width: 100%; height: 100%;",
                alt: ""
              },
              null
            )
          ])
      },
      { label: "排序", prop: "wares_order", minWidth: 50 },
      {
        label: "状态",
        minWidth: 130,
        cellRenderer: e => {
          var a;
          return g(
            A("el-switch"),
            {
              loading: (a = d.value[e.index]) == null ? void 0 : a.loading,
              modelValue: e.row.wares_status,
              "onUpdate:modelValue": r => (e.row.wares_status = r),
              "active-value": 1,
              "inactive-value": 2,
              "active-text": "已上架",
              "inactive-text": "已下架",
              "on-color": "#ffff",
              "inline-prompt": !0,
              onChange: () => V(e)
            },
            null
          );
        }
      },
      { label: "操作", fixed: "right", width: 220, slot: "operation" }
    ],
    S = D(() => [
      "!h-[20px]",
      "reset-margin",
      "!text-gray-500",
      "dark:!text-white",
      "dark:hover:!text-primary"
    ]);
  async function W(e) {
    const a = { wares_id: e.wares_id },
      r = JSON.stringify(a),
      t = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(r)) },
      s = await H(t);
    s.code == 200
      ? (c("删除成功", { type: "success" }), b())
      : c(s.msg, { type: "error" });
  }
  function J() {}
  function C(e) {}
  function L(e) {}
  function R(e) {}
  async function T(e) {
    const a = { wares_id: e.wares_id },
      r = JSON.stringify(a),
      t = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(r)) },
      s = await $(t);
    s.code == 200 && (m.value = s.data);
  }
  function U(e) {
    (B.text = `正在加载第${e}页...`),
      (i.value = !0),
      y(600).then(() => {
        i.value = !1;
      });
  }
  function V({ row: e, index: a }) {
    E.confirm(
      `确认要<strong>${
        e.wares_status === 1 ? "启用" : "停用"
      }</strong><strong style='color:var(--el-color-primary)'>${
        e.wares_name
      }</strong>banner吗?`,
      "系统提示",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        dangerouslyUseHTMLString: !0,
        draggable: !0
      }
    )
      .then(() => {
        d.value[a] = Object.assign({}, d.value[a], { loading: !0 });
        const r = { wares_id: e.wares_id, wares_status: e.wares_status },
          o = JSON.stringify(r),
          s = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(o)) };
        q(s),
          setTimeout(() => {
            (d.value[a] = Object.assign({}, d.value[a], { loading: !1 })),
              c("已成功修改banner状态", { type: "success" });
          }, 300);
      })
      .catch(() => {
        e.wares_status === 1 ? (e.wares_status = 2) : (e.wares_status = 1);
      });
  }
  async function k(e) {
    (i.value = !0), (w.value = e);
    const r = JSON.stringify({ page: 1, pagesize: 999, type: e, str: "warse" }),
      t = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(r)) },
      s = await v(t);
    s.code === 200
      ? ((u.value = s.data.data),
        (p.total = s.data.total),
        setTimeout(() => {
          i.value = !1;
        }, 500))
      : c(s.msg, { type: "error" });
  }
  async function I() {
    const e = { page: 1, pagesize: 999, str: "warse", type: w.value },
      a = JSON.stringify(e),
      o = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(a)) },
      t = await v(o);
    t.code === 200
      ? ((u.value = t.data.data),
        (p.total = t.data.total),
        setTimeout(() => {
          i.value = !1;
        }, 500))
      : c(t.msg, { type: "error" });
  }
  const O = e => {
    location.reload();
  };
  async function M() {
    const a = JSON.stringify({ page: 1, pagesize: 20, str: "warse" }),
      o = { value: n.enc.Base64.stringify(n.enc.Utf8.parse(a)) },
      t = await P(o);
    t.code === 200
      ? ((f.value = t.data),
        setTimeout(() => {
          i.value = !1;
        }, 500))
      : c(t.msg, { type: "error" });
  }
  return (
    F(() => {
      y().then(() => {
        const { setWatermark: e } = j(_.value.getTableDoms().tableWrapper);
        e("后台项目", {
          font: "16px Microsoft YaHei",
          globalAlpha: 0.8,
          forever: !0,
          width: 252,
          height: 80
        });
      }),
        I(),
        M();
    }),
    {
      loading: i,
      columns: x,
      dataList: u,
      pagination: p,
      buttonClass: S,
      orderInfo: m,
      dataTypeList: f,
      handleLookUserDatil: T,
      onSearch: k,
      resetForm: O,
      handleaddUser: J,
      handleDelete: W,
      handleSizeChange: C,
      handleCurrentChange: L,
      handleSelectionChange: R,
      onCurrentChange: U
    }
  );
}
export { G as useRole };
